<?php
namespace AuctionCore\AuctionOrder;
use AuctionCore\CarResource\Car;
//
// +------------------------------------------------------------------------+
// | PHP Version 5.4                                                        |
// +------------------------------------------------------------------------+
// | Copyright (c) All rights reserved.                                     |
// +------------------------------------------------------------------------+
// | 世纪车来车往(北京）网络科技有限公司 版权所有！                         |
// | TEL:010-63732365  HOTLINE:400-6688-365  EMAIL:clcw@clcw.com.cn         |
// | $Revision: 1.0 $                                                       |
// +------------------------------------------------------------------------+
// | Author: songaimin@clcw.com.cn  Blog:http://blog.csdn.net/samxx8        |
// +------------------------------------------------------------------------+
//


/**
* 拍单签约调度
* @author       爱民
*/
class SignDispatch extends AuOrder {
    
    /**
    * 分配
    * 返回线下任务id号。
    * @param    string $order_id    拍单编号
    * @param    string $target_id    签约顾问员工编号
    * @param    int $creater_id    任务创建员工编号
    * @param    string $remark    签约备注
    * @return   int/false
    */
    public function dispatch($target_id,$creater_id, $remark) {
        //预约地址
          $owner_confirm_log = M('owner_confirm_log');
          $confirm_info = $owner_confirm_log->where("order_id='{$this->auction_order_id}' and result=1 ")->find();

          //签约任务信息
          $task_info = array();
          $task_info['province']=$confirm_info['province'];
          $task_info['city']=$confirm_info['city'];
          $task_info['area']=$confirm_info['area'];
          $task_info['address']=$confirm_info['address'];
          $task_info['remark']=$remark;
          $task_info['target_id']=$target_id;
          $task_info['act_time']=$confirm_info['reserve_time'];
          $task_info['order_id']=$this->auction_order_id;
          $now = date("Y-m-d H:i:s",time());
          $task_info['createtime']=$now;
          $m = M('offline_task');
          $task_id = $m->add($task_info);          
          return $task_id;
    }
    
    /**
    * 签约成功
    * 保存付款信息，更新拍单状态"待付首款"。
    * 返回签约记录id
    * @param    array $sig_info    成功签约信息
    *                         [transfer_proc:过户手续，payee_name:收款人姓名，deposit_bank:开户行，payee_account:收款人帐号,签约时间，备注]
    * @param @emp_id  执行人员工编号 
    * @return   int
    */
    public function sign_sucess($sig_info,$emp_id) {
        $sig_info['order_id'] = $this->auction_order_id;
        $sig_info['emp_id'] = $emp_id;
        $sig_info['result'] = 1; //结果
        $now = date("Y-m-d H:i:s",time());
        $sig_info['createtime'] = $now; //签约时间

        $m = M('signature_log');
        $id = $m->add($sig_info);
        if($id){
            //更改拍单"待付首款"
            $ok = $this->update(array('au_status'=>8));
        }
        return $id;
    }
    
    /**
    * 签约继续跟踪
    * @param    array $info    [transfer_proc：过户手续,next_trace_time：下次跟踪时间,remark：备注]
    * @param @emp_id 执行人员工编号
    * @return   int
    */
    public function con_trace($sig_info,$emp_id) {
        $sig_info['order_id'] = $this->auction_order_id;
        $sig_info['emp_id'] = $emp_id;
        $sig_info['result'] = 2; //结果
        $now = date("Y-m-d H:i:s",time());
        $sig_info['createtime'] = $now; //签约时间

        $m = M('signature_log');
        $id = $m->add($sig_info);

        return $id;
    }
    
    /**
    * 签约失败,更改车源“交易失败” ,更改拍单“拍单失败_签约失败"
    * @param    array $info    签约信息
    *                         [过户手续,备注]
    * @return   int
    */
    public function sign_fail($sig_info,$emp_id) {
        $sig_info['order_id'] = $this->auction_order_id;
        $sig_info['emp_id'] = $emp_id;
        $sig_info['result'] = 3; //结果
        $now = date("Y-m-d H:i:s",time());
        $sig_info['createtime'] = $now; //签约时间

        $m = M('signature_log');
        $id = $m->add($sig_info);
        if($id){
            //更改拍单“拍单失败_签约失败"
            $ok = $this->update(array('au_status'=>12,'au_fail_type'=>3));

            //更改车源“交易失败” 
            $au_detail = $this->detail();
            $car = new Car($au_detail['car_id']);
            $ok = $car->update(array('car_status'=>8));
        }
        return $id;
    }
}

?>